﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using T4UtilityBelt.Templates;

namespace T4UtilityBelt.DataDesigns.Renderers
{
    public class RendererCollection : Collection<IRenderer>
    {
        private readonly Template _template;

        public RendererCollection(Template template)
        {
            _template = template;
        }

        public Template Template
        {
            get { return _template; }
        }


        public IRenderer FindRenderer(Property property)
        {
            if (property != null)
            {
                foreach (IRenderer renderer in this)
                {
                    if (renderer.EntityType.IsInstanceOfType(property))
                    {
                        return renderer;
                    }
                }
            }
            return null;
        }

        protected override void InsertItem(int index, IRenderer item)
        {
            item.Template = Template;
            base.InsertItem(index, item);
        }
    }
}